/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
**/
define("pages/jbjl/jbjl_doc", [
        "../../common/componts.js",
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate"
    ],
    function(require) {
        var componts = require("../../common/componts");
        var queryTableId="awdDocTableId";
        var selectid;

        var getQueryDataGrid = function(){
            return $("#"+queryTableId);
        };

        var tableInit=function(){
            componts.initTable(queryTableId,{
                url:"/jbjl/list",
                title:'',
                fit:true,
                // firstLoad:true,
                width:'100%',
                columns :  [
                    {
                        field: 'id',
                        title: '序号',
                        width:30,
                        formatter: function(value, rowData, rowIndex){
                            return '<input type="radio" name="ryRadio" id="ryRadio' + rowIndex + '" value="' + rowData.id + '" />';
                        }}
                    ,{field:'jsh',title:'拘室号',hidden:true,width:30,sortable:'false',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xm',title:'姓名',hidden:true,width:50,sortable:'false',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jq',title:'拘区',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jbr',title:'交班人',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jsr',title:'接收人',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'lastnum',title:'上次交班人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'mustnum',title:'当前应有人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'currnum',title:'当前实际人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'todayinnum',title:'今天入所人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'todayoutnum',title:'今天出所人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jstzinnum',title:'拘室调整进入人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jstzoutnum',title:'拘室调整出去人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'tsnum',title:'办理提审人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'lshjnum',title:'律师会见数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jshjnum',title:'亲属会见数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'lslsnum',title:'临时离所数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'swjynum',title:'所外就医数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'todaypjnum',title:'今天判决人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'zdrynum',title:'重点人员数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'zdbhnum',title:'重点病号数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'syjjnum',title:'使用戒具人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jbnum',title:'禁闭人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'ygnum',title:'严管人数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'sknum',title:'剩余手铐数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jlnum',title:'剩余脚镣数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jsnum',title:'剩余警绳数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'ysnum',title:'交班时钥匙数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'ssdnum',title:'交班时搜索灯数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'dtnum',title:'交班时电台数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jjnum',title:'警戒数量',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'zdzly',title:'中队长留言',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jbly',title:'交班留言',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'flag',title:'标志',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jsbh',title:'监所编号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'gjly',title:'管教留言',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'ysly',title:'医生留言',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'ywyc',title:'有无异常',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jbqk',title:'交班情况',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'sldly',title:'所领导留言',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'jjbsj',title:'交接班时间',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
            ,{field:'operate',title:'详细信息',align:'center',width : 60,
                formatter:function(value, row, index){
                return '<a href="#" data-target="#ckPhoto" value="'+index+'" data-toggle="modal" class="easyui-linkbutton awd-doc-view-detail"><img src="../../img/xq.png"></a>';
            }}
            ] ,
            //基本信息双击事件
            onDblClickRow:function(rowIndex, rowData){
                $("input[name='ryRadio']")[rowIndex].checked = true;
                getQueryDataGrid().datagrid("selectRow", rowIndex);
                selectid=rowData.id;
            },
            onLoadSuccess:function(data){
                if(data.total>0){
                getQueryDataGrid().datagrid("selectRow", 0);
                $("input[name='ryRadio']")[0].checked = true;
            }
                //$("a[name='opera']").each(function(){
                //    $(this).on('click',function () {
                //        var index = $(this).attr('value');
                //        var jbxx = data.rows[index];
                //        kss.initJbxxxx(jbxx.gcbh,jbxx.rybh,jbxx.xm+"--详细信息");
                //    });
                //});
            },
            //单击行选中取消事件
            onClickRow:function(rowIndex, rowData){
                if(selectid!=rowData.id){
                $("input[name='ryRadio']")[rowIndex].checked = true;
                selectid=rowData.id;
            }else{
                getQueryDataGrid().datagrid("unselectRow",rowIndex);
                $("input[name='ryRadio']")[rowIndex].checked = false;
                getQueryDataGrid().datagrid('clearSelections');
                selectid="";
            }
            }
            });
            //页面高度自适应
            getQueryDataGrid().datagrid('resize',{
                height:($(window).height()-150)
            });
            };

            /**
             * 数据列表刷新加载
             */
            var loadDataGrid = function(){
                var formData = $(".awd-doc-form").serializeObject();
                var queryParams = $.extend({},formData,{"state":"R8"});
                getQueryDataGrid().datagrid('clearSelections');
                getQueryDataGrid().datagrid('load',queryParams);
            };

        var bindAction=function(){
            //查询
            $(".awd-doc-query-btn").on("click",function(){
                loadDataGrid();
            });
            //管理文书
            $(".manage-doc-btn").on("click",function(){
                alert("管理文书")
            });
            //导出Excel
            $(".awd-doc-export-btn").on("click",function(){
                getQueryDataGrid().datagrid('toExcel',{"filename":"交班记录.xls"});
            });

            //单击行详情
            $(document).on('click','.awd-doc-view-detail',function(){
                console.log('awd-doc-view-detail',$(this).attr("value"));
            });

            /**
             * 绑定回车事件
             */
            $(window).keydown(function(event) {
                if (event.keyCode == 13) {
                    loadDataGrid();
                }
            });

        };

        //初始化
        (function(){
            componts.initSelectPage(undefined);
            componts.initSelect(undefined,undefined,undefined);
            tableInit();
            bindAction();
        })()
});
